package com.jwaoo.chat.fragment.session;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.dx.as.fragment.TFragment;
import com.dx.as.listener.IViewInterface;
import com.jwaoo.chat.ChatConstants;
import com.jwaoo.chat.ChatHelpter;
import com.jwaoo.chat.Message;
import com.jwaoo.chat.R;
import com.jwaoo.chat.fragment.session.bean.SessionBean;
import com.jwaoo.chat.fragment.session.repository.ISessionInterface;
import com.jwaoo.chat.fragment.session.repository.SessionRep;
import com.jwaoo.chat.session.Extras;

import java.util.List;
import java.util.Map;

/**
 * Created by jwaoo on 2017/6/30.
 */

public class SessionFragment extends TFragment implements ISessionInterface {
    private RecyclerView recyclerView;
    private View emptyBg;
    private TextView emptyHint;
    private SessionRep sessionRep;

    @Override
    public void initRpo() {
        sessionRep = new SessionRep(getActivity(),this);
        sessionRep.initialataData();
    }

    @Override
    public void onResume() {
        super.onResume();
        sessionRep.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        sessionRep.onPause();
    }

    @Override
    public void initView() {
        emptyBg = findView(R.id.emptyBg);
        emptyHint = findView(R.id.message_list_empty_hint);
        recyclerView = findView(R.id.recycler_view);
        recyclerView.setAdapter(sessionRep.getAdapter());
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addOnItemTouchListener(sessionRep.getOnTouchListener());
    }

    @Override
    public int setLayoutI() {
        return R.layout.fragment_session;
    }

    @Override
    public void dataOpion() {
        sessionRep.getDataFromNetOrDB();
    }

    @Override
    public void onItemClick(SessionBean sessionBean) {
        ChatHelpter.currentSessionId = sessionBean.getFriend();
        ChatHelpter.startP2PSession(getActivity(),sessionBean.getFriend());
    }

    @Override
    public void onResponse(Object object) {
        List<SessionBean> list = (List<SessionBean>) object;
        emptyBg.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
        emptyHint.setHint(getString(R.string.session_empty));
    }

    @Override
    public void onFailure() {

    }



}
